#ifndef CLIENTSOCKET_H
#define CLIENTSOCKET_H

#include "client-socket_global.h"
#include <QThread>
#include "baseproto.h"
#include <uv.h>
#include "cnsComponent.h"

class CLIENTSOCKET_EXPORT ClientSocketProc : public CnsComponent
{
    Q_OBJECT
private:
    BaseProto       _proto;
    uv_tcp_t        _socket;
    uv_connect_t    _connect;
    uv_timer_t      _heartbeatMaker;
    uv_loop_t *     _loop;
    uv_async_t      _async;

public:
    inline uv_connect_t& getConnect()
    {
        return _connect;
    }
    inline uv_async_t* getAsync()
    {
        return &_async;
    }
    inline uv_tcp_t& getSocket()
    {
        return _socket;
    }
    inline BaseProto &getBaseProto()
    {
        return _proto;
    }
    inline uv_timer_t &getHeartbeatMaker()
    {
        return _heartbeatMaker;
    }
    inline uv_loop_t *getLoop()
    {
        return _loop;
    }
    inline void setLoop(uv_loop_t *loop)
    {
        _loop = loop;
    }
    inline QString getIp() {
        return property_ts("ip").toString();
    }
    inline int getPort(){
        return property_ts("port").toInt();
    }
    Q_INVOKABLE ClientSocketProc(){}
    int msgSend(uint32_t msgType, google::protobuf::Message& hbReq);
    static void _on_write(uv_write_t* req, int status);
};

CNS_COM_DECL_METATYPE(ClientSocketProc)

#endif // CLIENTSOCKET_H
